import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

class TokenStorage extends GetxController {
  late final GetStorage storageBox;

  String tokenName = 'token';

  String usernameKey = 'username';

  String passwordKey = 'password';

  @override
  onInit() {
    storageBox = GetStorage();
  }

  setToken(String token) {
    storageBox.write(tokenName, token);
  }

  getToken() {
    return storageBox.read(tokenName) ?? '';
  }

  deleteToken() async {
    return await storageBox.remove(tokenName);
  }

  setUsername(String name) {
    storageBox.write(usernameKey, name);
  }

  getUsername() {
    return storageBox.read(usernameKey) ?? '';
  }

  deleteUsername() {
    storageBox.remove(usernameKey);
  }

  setPassword(String password) {
    storageBox.write(passwordKey, password);
  }

  getPassword() {
    return storageBox.read(passwordKey) ?? '';
  }

  deletePassword() {
    storageBox.remove(passwordKey);
  }

  setEnv(bool isProduct) {
    storageBox.write("env", isProduct);
  }

  bool getEnv() {
    return storageBox.read("env") ?? false;
  }
}
